package com.zhang.async;

import com.zhang.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import static com.zhang.common.Constant.MECHANICAL_EQUIPMENT_VERIFICATION_CODE;

/**
 * User: 张
 * Date: 2024-11-06
 * Time: 9:28
 * Description:
 */

@Component
public class EmailService {
    @Autowired
    JavaMailSenderImpl mailSender;


    @Value("${spring.mail.username}")
    public String SERVER_MAIL;
    @Async
    public void sendEmail(String email,String code){
        SimpleMailMessage mailMessage = new SimpleMailMessage();

        mailMessage.setSubject(MECHANICAL_EQUIPMENT_VERIFICATION_CODE);
        mailMessage.setText("验证码为: "+code);
        mailMessage.setTo(email);
        mailMessage.setFrom(SERVER_MAIL);

        mailSender.send(mailMessage);
    }
}
